package com.gitee.wsl.compose.animation.easing

import com.gitee.wsl.compose.animation.A

class BackInEasing(val s:Float=BACK):CalcEasing {
    override fun transform(t: Float, b: Float, c: Float, d: Float): Float {
        val t1=t/d
        return c * t1 * t1 * ((s + 1) * t1 - s) + b
    }
}

const val BACK=1.70158f

fun A.Easing.EaseInBack(black:Float=BACK) = BackInEasing(black)

 class BackOutEasing(val s:Float=BACK):CalcEasing {
    override fun transform(t: Float, b: Float, c: Float, d: Float): Float {
        val t1=t/d-1
        return c*(t1*t1*((s+1)*t1 + s) + 1) + b
    }
}

fun A.Easing.EaseOutBack(black:Float=BACK) = BackOutEasing(black)

 class BackInOutEasing(val s:Float=BACK):CalcEasing {
    override fun transform(t: Float, b: Float, c: Float, d: Float): Float {
        var t1= t / (d / 2)
        if (t1 < 1) return c / 2 * (t1 * t1 * ((s + 1) * t1 - s)) + b
        t1-=2
        return c / 2 * (t1 * t1 * ((s + 1) * t1 + s) + 2) + b
    }
}

fun A.Easing.EaseInOutBack(black:Float=BACK) = BackInOutEasing(black)